package com.ltkj.shop.service.impl;

import java.math.BigDecimal;
import java.util.List;
import com.ltkj.common.core.utils.DateUtils;
import com.ltkj.common.datascope.annotation.DataScope;
import com.ltkj.common.security.utils.SecurityUtils;
import com.ltkj.shop.domain.ShopHotel;
import com.ltkj.shop.domain.vo.ShopHotelRoomVo;
import com.ltkj.shop.mapper.ShopHotelMapper;
import com.ltkj.shop.mapper.ShopHotelRoomBizMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ltkj.shop.mapper.ShopHotelRoomMapper;
import com.ltkj.shop.domain.ShopHotelRoom;
import com.ltkj.shop.service.IShopHotelRoomService;

/**
 * 酒店房间Service业务层处理
 * 
 * @author xupf
 * @date 2023-08-29
 */
@Service
public class ShopHotelRoomServiceImpl implements IShopHotelRoomService 
{
    @Autowired
    private ShopHotelRoomMapper shopHotelRoomMapper;
    @Autowired
    private ShopHotelMapper shopHotelMapper;
    @Autowired
    private ShopHotelRoomBizMapper shopHotelRoomBizMapper;

    /**
     * 查询酒店房间
     * 
     * @param id 酒店房间主键
     * @return 酒店房间
     */
    @Override
    public ShopHotelRoomVo selectShopHotelRoomById(Long id)
    {
        return shopHotelRoomBizMapper.selectShopHotelRoomById(id);
    }

    /**
     * 查询酒店房间列表
     * 
     * @param shopHotelRoom 酒店房间
     * @return 酒店房间
     */
    @Override
    @DataScope(storeAlias = "hr")
    public List<ShopHotelRoom> selectShopHotelRoomList(ShopHotelRoom shopHotelRoom)
    {
        return shopHotelRoomBizMapper.selectShopHotelRoomList(shopHotelRoom);
    }

    /**
     * 移动端查询酒店房间列表
     *
     * @param shopHotelRoom 酒店房间
     * @return 酒店房间
     */
    @Override
    public List<ShopHotelRoom> selectList(ShopHotelRoom shopHotelRoom)
    {
        return shopHotelRoomBizMapper.selectList(shopHotelRoom);
    }

    /**
     * 新增酒店房间
     * 
     * @param shopHotelRoom 酒店房间
     * @return 结果
     */
    @Override
    public ShopHotelRoom insertShopHotelRoom(ShopHotelRoom shopHotelRoom)
    {
        ShopHotel shopHotel = shopHotelMapper.selectShopHotelById(shopHotelRoom.getHotelId());
        shopHotelRoom.setSysStoresId(shopHotel.getSysStoresId());
        shopHotelRoom.setCreateTime(DateUtils.getNowDate());
        shopHotelRoom.setCreateBy(SecurityUtils.getLoginUser().getUsername());
        shopHotelRoom.setUserId(SecurityUtils.getLoginUser().getUserid());
        shopHotelRoom.setIsDel("0");

        // 转换金额 元 -> 分
        shopHotelRoom.setPrice(shopHotelRoom.getPrice().multiply(new BigDecimal(100)));
        shopHotelRoom.setPriceSrc(shopHotelRoom.getPriceSrc().multiply(new BigDecimal(100)));
        shopHotelRoomMapper.insertShopHotelRoom(shopHotelRoom);
        return shopHotelRoom;
    }

    /**
     * 修改酒店房间
     * 
     * @param shopHotelRoom 酒店房间
     * @return 结果
     */
    @Override
    public int updateShopHotelRoom(ShopHotelRoom shopHotelRoom)
    {
        shopHotelRoom.setUpdateTime(DateUtils.getNowDate());
        shopHotelRoom.setUpdateBy(SecurityUtils.getLoginUser().getUsername());
        // 转换金额 元 -> 分
        shopHotelRoom.setPrice(shopHotelRoom.getPrice().multiply(new BigDecimal(100)));
        shopHotelRoom.setPriceSrc(shopHotelRoom.getPriceSrc().multiply(new BigDecimal(100)));
        return shopHotelRoomMapper.updateShopHotelRoom(shopHotelRoom);
    }

    /**
     * 批量删除酒店房间
     * 
     * @param ids 需要删除的酒店房间主键
     * @return 结果
     */
    @Override
    public int deleteShopHotelRoomByIds(Long[] ids)
    {
        return shopHotelRoomBizMapper.deleteShopHotelRoomByIds(ids);
    }

    /**
     * 删除酒店房间信息
     * 
     * @param id 酒店房间主键
     * @return 结果
     */
    @Override
    public int deleteShopHotelRoomById(Long id)
    {
        return shopHotelRoomBizMapper.deleteShopHotelRoomById(id);
    }
}
